//
//  TJTemplatePresent.m
//  BaoDian
//
//  Created by mac on 2024/8/15.
//

#import "TJTemplatePresent.h"
#import "TJTemplateModel.h"

@implementation TJTemplatePresent

+ (void)loadCarouselDataComplete:(void (^__nullable)(NSArray *datas, NSError * _Nullable error))complete {
    
    [TJNetworking.shareNetwork GET:@"/admin/sysAppCarousel/app" parameters:@{
        @"pageNum": @1,
        @"pageSize": @60,
    } success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        !complete ?: complete(data, nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(nil, error);
    }];
}

+ (void)loadIndustryListComplete:(void (^__nullable)(NSArray *datas, NSError * _Nullable error))complete {
    [TJNetworking.shareNetwork GET:@"/escrow/appTemplate/industryList" parameters:nil success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        NSMutableArray *arr = [NSMutableArray array];
        for (NSDictionary *dict in data) {
            NSMutableDictionary *Mdict = [NSMutableDictionary dictionary];
            [Mdict setValue:dict[@"name"] forKey:@"name"];
            if ([dict[@"id"] isKindOfClass:NSString.class]) {
                [Mdict setValue:dict[@"id"] forKey:@"type"];
            } else {
                [Mdict setValue:@"0" forKey:@"type"];
            }
            [arr addObject:Mdict];
        }
        [USERDEFAULTS setObject:arr forKey:moduleListKey];
        !complete ?: complete(arr, nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(nil, error);
    }];
}

+ (void)loadIndustryDataWithId:(NSString *)Id pageIndex:(NSInteger)pageIndex complete:(void (^__nullable)(NSArray *datas, NSError * _Nullable error))complete {
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setValue:@(pageIndex) forKey:@"pageNum"];
    [parameters setValue:@20 forKey:@"pageSize"];
    if ([Id longLongValue]) {
        [parameters setValue:Id forKey:@"industryId"];
    }
    [TJNetworking.shareNetwork GET:@"/escrow/appTemplate/appPage" parameters:parameters success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        !complete ?: complete([TJTemplateModel mj_objectArrayWithKeyValuesArray:data], nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(nil, error);
    }];
}

+ (void)loadTempleteGatherDataWithId:(NSString *)Id pageIndex:(NSInteger)pageIndex complete:(void (^__nullable)(NSArray *datas, NSError * _Nullable error))complete {
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setValue:@(pageIndex) forKey:@"pageNum"];
    [parameters setValue:@20 forKey:@"pageSize"];
    [parameters setValue:Id forKey:@"id"];
    [TJNetworking.shareNetwork GET:@"/escrow/appTemplate/heJiDetailList" parameters:parameters success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        
        NSMutableArray *datas = [NSMutableArray array];
        for (NSMutableDictionary *dict in data) {
            
            TJTemplateModel *model = [[TJTemplateModel alloc] init];
            model.videoUrl = dict[@"videoUrl"];
            model.Id = dict[@"id"];
            model.videoName = dict[@"videoName"];
            model.status = dict[@"status"];
            model.clockTimes = dict[@"clockTimes"];
            model.usedTimes = dict[@"usedTimes"];
            model.dataDate = dict[@"dataDate"];
            model.type = @"1";
            
            [datas addObject:model];
        }
        !complete ?: complete(datas, nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(nil, error);
    }];
}

+ (void)loadTemplateGatherDetailDataWithId:(NSString *)Id complete:(void (^__nullable)(NSDictionary *data, NSError * _Nullable error))complete {
    
    if (isEmptyString(Id)) return;

    [TJNetworking.shareNetwork GET:@"/escrow/appTemplate/heJiDetail" parameters:@{
        @"id": Id
    } success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        !complete ?: complete(data, nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(nil, error);
    }];
}


+ (void)loadTemplateDetailDataWithId:(NSString *)Id complete:(void (^__nullable)(NSDictionary *data, NSError * _Nullable error))complete {
    
    if (isEmptyString(Id)) return;
    
    [TJNetworking.shareNetwork GET:@"/escrow/appTemplate/detail" parameters:@{
        @"id": Id
    } success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        !complete ?: complete(data, nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(nil, error);
    }];
}

+ (void)getVersionDataComplete:(void (^__nullable)(NSDictionary *data, NSError * _Nullable error))complete {

    [TJNetworking.shareNetwork GET:@"/admin/sys/appVersion/getIosLastVersion" parameters:nil success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        !complete ?: complete(data, nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(nil, error);
    }];
}
 
+ (void)saveTemplateDetailDataWithId:(NSString *)Id videoId:(NSString *)videoId materialJsonObj:(NSDictionary *)materialJsonObj complete:(void (^__nullable)(NSDictionary *data, NSError * _Nullable error))complete {
    [TJNetworking.shareNetwork POSTBodyJSON:@"/escrow/appTemplate/editVideo" parameters:@{
        @"materialJsonObj": materialJsonObj,
        @"templateId": Id,
        @"videoId": videoId
    } success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        !complete ?: complete(data, nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(nil, error);
    }];
}

+ (void)queryVideoResultDataWithId:(NSString *)Id  complete:(void (^__nullable)(NSDictionary *data, NSError * _Nullable error))complete {
    [TJNetworking.shareNetwork POST:@"/escrow/appTemplate/getTaskStatus" parameters:@{
        @"id": Id,
    } success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        !complete ?: complete(data, nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(nil, error);
    }];
}

+ (void)createShareId:(NSString *)text hasPoi:(BOOL)hasPoi videoEditId:(NSString *)videoEditId complete:(void (^__nullable)(NSDictionary *data, NSError * _Nullable error))complete {
    [TJNetworking.shareNetwork POSTBodyJSON:@"/escrow/appTemplate/toClock" parameters:@{
        @"text": text,
        @"videoEditId": videoEditId,
        @"hasPoi": @(hasPoi)
    } success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        !complete ?: complete(data, nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(nil, error);
    }];
    
}

+ (void)updateClockPlanWithId:(NSString *)Id status:(NSString *)status complete:(void (^__nullable)(NSError * _Nullable error))complete {
    [TJNetworking.shareNetwork POSTBodyJSON:@"/escrow/appTemplate/updateStatus" parameters:@{
        @"id": Id,
        @"status": status
    } success:^(NSDictionary * _Nonnull responseObject, id  _Nonnull data) {
        !complete ?: complete(nil);
    } failure:^(NSError * _Nonnull error) {
        !complete ?: complete(error);
    }];
}

@end
